const conn = require('../../libs/DB/Conn');
const utils = require('../../libs/Utils');
const operationRecord = require("../sys/operationRecordAction");
module.exports = async function (params) {
    let userId = params.userId;
    let oldPwd = utils.encrypt(params.oldPwd);
    let newPwd = utils.encrypt(params.newPwd);
    let checkUserSql = `SELECT
                          *
                           FROM
                            user_file uf
                           WHERE user_id = ?
                             AND PASSWORD = ?`;
    let queryResult = await conn(checkUserSql, [userId, oldPwd]);
    if (queryResult.length) {
        let updateSql = `update user_file SET password = ? WHERE user_id = ?`;
        await conn(updateSql, [newPwd, userId]);
        await operationRecord(params);
        return {success: true, message: '修改成功'}
    } else {
        return {success: false, message: '密码错误'}
    }
}